/*
 * DateFilenameGenerator
 * Created: Dec 21, 2006 
 * by abargnesi<mailto:abargnesi@aquent.com/>
 */
package com.den4.jynform.tasks;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map;

public class CurrentDateFilenameGenerator implements FilenameGenerator {
    private Map<Integer,Integer> offsets;
    
    private String dateFormat;
    
    public Map<Integer,Integer> getOffsets() {
        return offsets;
    }
    
    public void setOffsets(Map<Integer,Integer> offsets) {
        this.offsets = offsets;
    }
    
    public String getDateFormat() {
        return dateFormat;
    }
    
    public void setDateFormat(String dateFormat) {
        this.dateFormat = dateFormat;
    }

    /**
     * Read out date 
     */
    public String generate() {
        SimpleDateFormat df = new SimpleDateFormat(dateFormat);
        Calendar today = Calendar.getInstance();
        
        //Apply offsets
        for(Map.Entry<Integer, Integer> offset : offsets.entrySet()) {
            today.add(offset.getKey(), offset.getValue());
        }
        
        return df.format(today.getTime());
    }
}
